﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using olierFrm.MVC;
using System.Data;
using olierFrm.Extensions.EString;

namespace MvcApplication1.Controllers
{
    public class TicketController : Controller
    {
        [Compress, AcceptVerbs(HttpVerbs.Get)]
        public string Site()
        {
            SmartPage.SmartPageData data = SmartPage.GetSmartPageData(base.RouteData);
            List<object> oo = new List<object>();
            DataTable dtThreeCodeCN = data.StdQuery.Tables["ThreeCodeCN"];
            for (int i = 0; i < dtThreeCodeCN.Rows.Count; i++)
            {
                oo.Add(new
                {
                    threeCode = dtThreeCodeCN.Rows[i]["ThreeCode"].ToString().Trim(),
                    label = dtThreeCodeCN.Rows[i]["CityDescCN"].ToString().Trim(),
                    sitePY2 = dtThreeCodeCN.Rows[i]["CityDescEN"].ToString().Trim(),
                    sitePY = dtThreeCodeCN.Rows[i]["CityPY"].ToString().Trim()
                });
            }
            return oo.ToJSON();
        }
        [Compress, AcceptVerbs(HttpVerbs.Get)]
        public ActionResult Index()
        {
            SmartPage.SmartPageData data = SmartPage.GetSmartPageData(base.RouteData);
            //WSFlights wsFlights = new WSFlights();
            //base.ViewData["MinSpecialsTicket"] = wsFlights.MinSpecialsTicket();
            base.ViewData["data"] = data;
            return base.View();
        }
        [AcceptVerbs(HttpVerbs.Get), Compress]
        public string BunkPrice()
        {
            SmartPage.SmartPageData data = SmartPage.GetSmartPageData(base.RouteData);
            //WSFlights wsFlights = new WSFlights();
            //string price = wsFlights.GetFlightAirlineBunkPrice(base.Request.QueryString["LEAVEDATE"], base.Request.QueryString["LEAVECODE"], base.Request.QueryString["ARRIVALCODE"], base.Request.QueryString["TIME"], base.Request.QueryString["AIRLINE"], base.Request.QueryString["BUNK"]);
            string price = "1000";
            string result;
            if (price != "")
            {
                string[] prices = price.Split(new char[]
				{
					'|'
				});
                string yPrice = prices[0].Substring(prices[0].IndexOf("：") + 1).Split(new char[]
				{
					','
				})[0];
                string cPrice = prices[1].Substring(prices[0].IndexOf("：") + 1).Split(new char[]
				{
					','
				})[0];
                result = yPrice + "|" + cPrice;
            }
            else
            {
                result = "";
            }
            return result;
        }
        [Compress, AcceptVerbs(HttpVerbs.Get)]
        public ActionResult List()
        {
            SmartPage.SmartPageData data = SmartPage.GetSmartPageData(base.RouteData);
            string leaveDate = base.Request.QueryString["LEAVEDATE"];
            string leaveCode = base.Request.QueryString["LEAVECODE"];
            string arrivalCode = base.Request.QueryString["ARRIVALCODE"];
            if (leaveDate.Length == 0 || leaveCode.Length == 0 || arrivalCode.Length == 0)
            {
                throw new HttpException(404, "无法找到资源。");
            }
            //WSFlights wsFlights = new WSFlights();
            //DataSet returnData = null;
            //try
            //{
            //    bool isAdmin = false;
            //    if (LoginUser.UserInfo != null && LoginUser.UserInfo.RoleID == "001")
            //    {
            //        isAdmin = true;
            //    }
            //    returnData = wsFlights.GetTickPrice(leaveDate, leaveCode, arrivalCode, isAdmin);
            //}
            //catch (Exception var_7_CD)
            //{
            //    DataTable dtError = new DataTable("错误信息");
            //    returnData = new DataSet();
            //    returnData.Tables.Add(dtError);
            //}
            //base.ViewData["data"] = returnData;
            base.ViewData["SmartPageData"] = data;
            return base.View();
        }
    }
}
